<template>
	<view class="container">
		<loading :show="loading_show"></loading>
		<customHead
			title="积分"
			isShowBackArrow
			:titlePaddingLeft="30"
		>
			<view class="title">
				<view class="left">
					<text class="text1">我的积分：</text>
					<text class="text2">{{userInfo.integral}}</text>
				</view>
				<view class="right" @click="gotoRecord">
					<text>积分明细</text>
					<u-icon name="arrow-right" color="#fff" size="14"></u-icon>
				</view>
			</view>
		</customHead>
		<scroll-view
			scroll-y="true"
			class="main_scroll"
			v-if="naviHeight"
			:style="{paddingTop: `${naviHeight}px`}"
			:refresher-triggered="refresher_show"
			@refresherrefresh="refresherrefresh"
			@scrolltolower="scrolltolower"
			:scroll-with-animation="true"
			:refresher-enabled="true"
			:scroll-top="scrollTop"
		>
			<view class="main_content">
				<view class="goodsList_box">
					<view class="goods_item" @click="gotoDetail(item.id)" v-for="(item, index) in pointGoodsList" :key="index">
						<view class="goodsTitle_box">
							<view class="image">
								<image :src="item.rotationImgsJson[0]" lazy-load mode="aspectFill"></image>
							</view>
							<view class="title">
								<text class="title_text">{{item.goodsName}}</text>
								<text class="desc_text">{{item.goodsRemarks}}</text>
								<view class="hotSale">
									<text>热销</text>
								</view>
								<!-- <view class="coupondesc">
									<view class="coupon">
										<view class="text1">券</view>
										<view class="text2">满600减10</view>
									</view>
								</view> -->
								<view class="price">
									<view class="">
										<text>{{item.goodsPrice}}积分</text>
									</view>
									<view class="exchangeImme">立即兑换</view>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import { getIntegralGoodsList } from "@/tools/request/api.js"
	export default {
		data() {
			return {
				couponList: [],
				couponIndex: -1,
				orderPage: {
					page: 1,
					sizes: 10,
					total: 0,
					hasNextPage: false
				},
				pointGoodsList: [],
				refresher_show: false
			};
		},
		onLoad () {
			this.getgoodsList(true);
		},
		methods: {
			gotoDetail (id) {
				uni.navigateTo({
					url: `/subpack_my/integral/integralDetail?id=${id}`
				})
			},
			gotoRecord () {
				uni.navigateTo({
					url: `/subpack_my/integral/integralRecord`
				})
			},
			// 获取积分兑换商品的商品列表
			getgoodsList(clear){
				this.loading_show = true;
				let postdata={
					businessId: this.businessId,
					page: this.orderPage.page
				}
				getIntegralGoodsList(postdata).then(res=>{
					if(res.code != 200) return uni.$showMsg();
					this.orderPage.total = res.body.pages;
					this.orderPage.hasNextPage = res.body.hasNextPage;
					let list = res.body.list;
					list.forEach((item) => {
						if (item.rotationImgsJson) {
							item.rotationImgsJson = JSON.parse(item.rotationImgsJson);
						}
					})
					if(clear){
						this.pointGoodsList = list;
					}else{
						this.pointGoodsList = this.pointGoodsList.concat(list);
					}
					this.loading_show = false;
					if (this.refresher_show) {
						this.refresher_show = false;
					}
				})
			},
			// 下拉刷新
			refresherrefresh () {
				this.refresher_show = true;
				this.orderPage.page = 1;
				this.getgoodsList(true);
			},
			// 滚动到底部加载更多
			scrolltolower () {
				if (!this.orderPage.hasNextPage) return;
				this.orderPage.page++;
				this.getgoodsList();
			},
		}
		
	}
</script>

<style lang="scss">
	page{
		width: 100vw;
		height: 100vh;
		background: linear-gradient(to bottom, #FF0006 300rpx, #F6D5C3 500rpx, #f8f8f8 700rpx);
	}
</style>

<style lang="scss" scoped>
	.container{
		width: 100vw;
		
		.title{
			display: flex;
			justify-content: space-between;
			padding: 0 30rpx;
			box-sizing: border-box;
			
			
			.left{
				display: flex;
				align-items: center;
				
				.text1{
					color: #fff;
				}
				.text2{
					font-size: 60rpx;
					font-weight: bold;
					color: #fff;
				}
			}
			.right{
				height: 70rpx;
				padding: 0 16rpx;
				border-radius: 35rpx;
				display: flex;
				justify-content: center;
				align-items: center;
				background-color: rgba(255,255,255,0.4);
				color: #fff;
			}
		}
		
		.main_scroll{
			width: 100%;
			height: 100vh;
			box-sizing: border-box;
			
			.main_content{
				width: 100%;
				
				.goodsList_box{
					box-sizing: border-box;
					margin-bottom: 30rpx;
					padding: 0 20rpx;
					padding-bottom: 40rpx;
					
					.goods_item{
						padding: 20rpx 20rpx;
						box-sizing: border-box;
						margin-top: 20rpx;
						margin-bottom: 20rpx;
						background-color: #fff;
						border-radius: 20rpx;
					
						.goodsTitle_box{
							display: flex;
							align-items: center;
							
							.image{
								width: 220rpx;
								height: 220rpx;
								border-radius: 20rpx;
								
								image{
									width: 100%;
									height: 100%;
									border-radius: 20rpx;
								}
							}
							
							.title{
								flex: 1;
								display: flex;
								flex-direction: column;
								margin-left: 20rpx;
								box-sizing: border-box;
								white-space: nowrap;
								overflow: hidden;
								text-overflow: ellipsis;
								
								.title_text{
									font-size: 30rpx;
									padding-bottom: 14rpx;
									overflow: hidden;
									white-space: normal;
									text-overflow: ellipsis;
									-webkit-line-clamp: 2;
									-webkit-box-orient: vertical;
								}
								.desc_text{
									color: #7a7a7a;
									font-size: 24rpx;
									overflow: hidden;
									text-overflow: ellipsis;
								}
								.couponAfter{
									
									text{
										padding: 4rpx 16rpx;
										background-color: #FF0000;
										color: #fff;
										font-size: 26rpx;
										border-radius: 10rpx;
									}
								}
								.hotSale{
									padding: 4rpx 0;
									
									text{
										padding: 4rpx 4rpx;
										background-color: #FFDEE2;
										color: #FF0000;
										font-size: 22rpx;
										border-radius: 10rpx;
									}
								}
								.coupondesc{
									display: flex;
									align-items: center;
									margin-top: 6rpx;
									
									.coupon{
										border: 1rpx solid #FF0000;
										display: flex;
										align-items: center;
										border-radius: 6rpx;
										
										.text1{
											width: 26rpx;
											padding: 4rpx 4rpx;
											background-color: #FF0000;
											color: #fff;
											font-size: 22rpx;
											border-radius: 6rpx;
										}
										.text2{
											padding: 0 4rpx;
											font-size: 22rpx;
											color: #FF0000;
										}
									}
								}
								.price{
									margin-top: 20rpx;
									font-size: 34rpx;
									color: #FF0000;
									font-weight: bold;
									display: flex;
									justify-content: space-between;
									align-items: center;
									
									span{
										font-size: 30rpx;
									}
									.image{
										width: 50rpx;
										height: 50rpx;
									}
									.exchangeImme{
										background-color: #df282f;
										color: #fff;
										font-size: 26rpx;
										border-radius: 40rpx;
										padding: 8rpx 30rpx;
									}
								}
							}
						}
					}
					.goods_item:last-child{
						border: none;
					}
				}
			}
		}
		
		
	}
</style>
